package com.bigdata;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *  1.加载驱动
 *  2.创建连接
 *  3.创建语句
 *  4.执行SQL 获取结果
 *  5.遍历结果
 *  
 */public class PhoenixCodeTest2 {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement pst = null;
        ResultSet rst = null;
        try {
            //1.加载驱动
            Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

            //2.创建连接
            conn = DriverManager.getConnection("jdbc:phoenix:node02,node03,node04:2181");

            //3.创建语句
            pst = conn.prepareStatement("select \"id\",\"name\",\"age\" from \"global_index_test\" where \"id\" = '1'");

            //4.执行sql，获取结果
            rst = pst.executeQuery();

            //5.遍历结果
            while(rst.next()){
                String id = rst.getString("id");
                String name = rst.getString("name");
                String age = rst.getString("age");
                System.out.println("id = "+id+",name = "+name+",age = "+age);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                rst.close();
                pst.close();
                conn.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
}